<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.app
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       cake
 * @subpackage    cake.app
 */
class AppController extends Controller {
  
  // ----------------------------
  // A list of flash message types - creating a pseudo-enumerated set to use when calling addFlashMsg().
  // This list of types will be used as CSS classes in the view, styled accordingly.
  var $flashError   = "error";
  var $flashWarning = "warning";
  var $flashInfo    = "info";
  var $flashSuccess = "success";
  var $flashMessage = "message";
  
  // added 10/8/11 so my layout files could access my new 'Menu' and 'Link' helpers
  // had to re-add the others (I think Cake adds them normally, but if you override the var 
  // like this, have to add them back in
  var $helpers = array('Html', 'Form' , 'Session' , 'Menu'  , 'Link', 'LessCss', 
                       'Js'  ,'MyForm', 'Elfinder', 'Tooltip');
  
  
  
  
  /**
   * Trying to implement a "multiple-flash-messages" solution - inspired by:
   * http://mrphp.com.au/code/multiple-flash-messages-style-cakephp but modifying it
   * to work for Cake 1.3 and my situation
   * 
   * @param string $message
   * @param string $type  Callers should use one of the AppController properties like "$this->flashError"
   *                      or "$this->flashWarning", etc to set the $type. This will ensure that the proper
   *                      string gets passed so the proper CSS class gets set for the message.
   */
	function addFlashMsg( $message, $type='message' ) {
    
    // First retrieve the existing msgs stored so we can append to them
		$messages = (array)$this->Session->read('Message.multiFlash');
    // append
		$messages[] = array(
			'message'=>$message, 
			//'element'=>'default',
      'element'=>'customFlashMessage',  // use my custom Cake 'element' when outputing msgs.
			'params'=>array('class'=>$type),
		);
    // re-store all the messages
		$this->Session->write('Message.multiFlash', $messages);
    
	} ///////////// end addFlashMsg() /////////////////////////

  /**
   * @override 
   * 
   * beforeRender() is called after the controller action is run, but before the view is rendered.
   *
   * I'm using it to call disableCache() to solve the browser back button problem of re-showing 
   * flash messages.  This forces the browser to get the view from the server, rather than from its
   * cached copy (which would show the flash messages again).
   * 
   */
  function beforeRender() {
    parent::beforeRender();
    
    $this->disableCache();
  }
  
  
    
  
} /////////////////////////////// end class //////////////////////////
